from pydantic import BaseModel, Field
from datetime import datetime
from typing import Optional, List, Union

# 创建群组请求模型
class RoomCreate(BaseModel):
    name: str = Field(..., description="群组名称")
    description: Optional[str] = Field(None, description="群组描述")
    avatar: Optional[str] = Field(None, description="群组头像")

# 更新群组请求模型
class RoomUpdate(BaseModel):
    name: Optional[str] = Field(None, description="群组名称")
    description: Optional[str] = Field(None, description="群组描述")
    avatar: Optional[str] = Field(None, description="群组头像")

# 邀请成员请求模型
class RoomMemberAdd(BaseModel):
    room_id: int = Field(..., description="群聊房间ID")
    user_ids: List[int] = Field(..., description="要邀请的用户ID列表")

# 房间成员查询参数
class RoomMemberQuery(BaseModel):
    room_id: int = Field(..., description="群聊房间ID")
    page: int = Field(1, description="页码")
    page_size: int = Field(20, description="每页数量")
    keyword: Optional[str] = Field(None, description="搜索关键词")

# 群成员信息模型
class RoomMember(BaseModel):
    id: int
    nickname: str
    avatar: Optional[str] = None
    role: int  # 0-普通成员 1-管理员 2-群主
    online: bool

# 群组详情响应模型
class RoomInfo(BaseModel):
    id: int
    conversationId: int
    roomId: int
    name: str
    description: Optional[str] = ""
    announcement: Optional[str] = ""
    avatar: Optional[str] = None
    ownerId: int
    memberCount: int
    onlineCount: int = 0
    createTime: str
    members: Optional[List[RoomMember]] = None

# 群组列表项响应模型
class RoomListItem(BaseModel):
    id: int
    conversationId: int
    roomId: int
    name: str
    description: Optional[str] = ""
    avatar: Optional[str] = None
    ownerId: int
    memberCount: int
    onlineCount: int = 0
    createTime: str

# 分页响应模型
class PageResponse(BaseModel):
    list: List[RoomMember]
    total: int
    page: int
    page_size: int 